package com.wdciti.sccp.iot;

import com.wdciti.sccp.iot.position.model.MeasureDataSet;
import com.wdciti.sccp.iot.position.model.MeasureDataValue;
import com.wdciti.sccp.iot.position.service.PositionDataService;
import com.wdciti.sccp.iot.position.service.PositionDataServiceImpl;

import com.wdciti.sccp.iot.tsdata.impl.iotdb.IotdbWrapper;
import org.apache.iotdb.session.pool.SessionPool;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Instant instant = Instant.parse("2023-06-17T13:50:25.000Z");
        System.out.println("Hello world!" + instant);
        SessionPool session = new SessionPool.Builder()
                .host("127.0.0.1")
                .port(6667)
                .user("root")
                .password("root")
                .maxSize(5)
                .build();

        try {
            PositionDataService service = new PositionDataServiceImpl(new IotdbWrapper(session));
            List<MeasureDataValue> list1 = service.getLastData("root.position.plat.p_1149351409343266818");
            System.out.println("list1:----");
            list1.forEach(measureDataValue -> System.out.println(measureDataValue.getKey() + ":" + measureDataValue.getValue()+":"+measureDataValue.getTimeStamp()));

            List<MeasureDataValue> list2 =service.getLastData("root.position.plat.p_1149351409343266818",Arrays.asList("high","channel"));
            System.out.println("list2:----");
            list2.forEach(measureDataValue -> System.out.println(measureDataValue.getKey() + ":" + measureDataValue.getValue()+":"+measureDataValue.getTimeStamp()));
            Instant startTime =  LocalDateTime.parse("2023-11-15T00:00:00").atZone(ZoneId.systemDefault()).toInstant();
            Instant endTime = LocalDateTime.parse("2023-11-16T00:00:00").atZone(ZoneId.systemDefault()).toInstant();
            MeasureDataSet set = service.getRawData("root.position.plat.p_1149351001308790784",startTime.toEpochMilli(),endTime.toEpochMilli());
            set.getTimeStamps();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
